#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <cmath>
using namespace std;

bool IsPrim(long long x)
{
    if (x < 2) return false;
    for (int i = 2; i <= sqrt(x); i++)
        if (x % i == 0) return false;
    return true;
}

int main()
{
    long long t, a, b;
    cin >> t;
    while (t--)
    {
        cin >> a >> b;
        if ((a == 1 && IsPrim(b)) || (b == 1 && IsPrim(a)))
            cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}